package com.example.im.immsgdemo;

import android.Manifest;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import io.rong.callkit.RongCallKit;
import io.rong.calllib.RongCallClient;
import io.rong.calllib.RongCallSession;
import io.rong.imkit.RongIM;
import io.rong.imlib.RongIMClient;

public class MainActivity extends AppCompatActivity {


    private ImChatManager mImChatManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mImChatManager = ImChatManager.getInstance();

        String[] arr = {
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.CAMERA,
                Manifest.permission.RECORD_AUDIO
        };


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(arr, 110);
        }
    }

    //{"code":200,"userId":"2","token":"UmrK3b9VglvaUs0Iyy2X30/YY7jGUTc5iZeAjZxE1nrilnhJ0GA4q6mKrORhVfrYC1rTkCfS5WcF9eenBWX/hw=="}
    //{"code":200,"userId":"1","token":"GsPnvQOXPFzklvvk9lGnzNgM5Z47ZDxf7YoFsJe/AIYmpEFn/A3w8rJRCkNByE6l3qoQKi+G+wwSp+mAiEMTWQ=="}

    public void login(View view) {
        String token = "GsPnvQOXPFzklvvk9lGnzNgM5Z47ZDxf7YoFsJe/AIYmpEFn/A3w8rJRCkNByE6l3qoQKi+G+wwSp+mAiEMTWQ==";

        mImChatManager.imConnon(token);
    }

    public void charIm(View view) {
        mImChatManager.startChat(this, "2", "用户名");
    }

    public void charImVideo(View view) {
        RongCallSession profile = RongCallClient.getInstance().getCallSession();

        if (profile != null && profile.getStartTime() > 0) {
            Toast.makeText(this, "正在通话中", Toast.LENGTH_SHORT).show();
            return;
        }

        RongCallKit.startSingleCall(this, "2", RongCallKit.CallMediaType.CALL_MEDIA_TYPE_VIDEO);
    }
}
